package com.fireXXX.job.analysis.crawler.boss;

import com.fireXXX.job.analysis.crawler.boss.constant.*;
import com.fireXXX.job.analysis.crawler.common.Page;
import com.fireXXX.job.analysis.crawler.common.DynamicPageTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class WebGather {

    @Autowired
    private DynamicPageTool dynamicPageTool;

    private String formatJobUrl = "https://www.zhipin.com/c%s/?query=%s&page=%d";

    private String formatCompanyUrl = "https://www.zhipin.com/gongsi/_zzz_c%s_iy%s_t%s_s%s/?page=%d";

    public String gatherJob(CityTypeEnum province, TechnicalTypeEnum tech, Page page) {
        String url = String.format(formatJobUrl, province.getText(), tech.getText(), page.getCurrent());
        return dynamicPageTool.getPageContent(url);
    }

    public String gatherCompany(CityTypeEnum city, IndustryTypeEnum industry, PublicStepTypeEnum publicStep, EmployeeNumberTypeEnum employeeNumber, Page page) {
        String url = String.format(formatCompanyUrl, city.getText(), industry.getText(), publicStep.getText(), employeeNumber.getText(), page.getCurrent());
        return dynamicPageTool.getPageContent(url);
    }

}
